package com.ks.controller;

import com.ks.pojo.Product;
import com.ks.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/product")
public class ProductController {

    @Value("${server.port}")
    private String port;

    @Autowired
    private ProductService productService;

    @GetMapping("/findAll")
    public List<Product> findAll() {
        return productService.findAll();
    }
    @GetMapping("/get/{id}")
    public Product getById(@PathVariable String id) {//参数名默认=id，变量名=id,http://localhost:3010/product/get/2
        return productService.getById(id);
    }
    @RequestMapping("/info")
    public Product infoById(@RequestParam String id) {//参数名默认=id，变量名=id,http://localhost:3010/product/get/2
        return productService.getById(id);
    }
    @GetMapping("/get2/{id}")
    public Product getById2(@PathVariable("id")  String id2) {//参数名=id，变量名=id2,http://localhost:3010/product/get/2
        return productService.getById(id2);
    }
    @GetMapping("/getp")
    public Product getByIdParam(@RequestParam String id) {//参数名=id,http://localhost:3010/product/getp?id=2
        return productService.getById(id);
    }
    @GetMapping("/getp2")
    public Product getByIdParam2(@RequestParam("id2") String id) {//参数名=id2,http://localhost:3010/product/getp2?id2=2
        return productService.getById(id);
    }
    @GetMapping("/getp3")
    public Product getByIdParam3(@RequestParam(value = "id3") String id) {//参数名=id3,http://localhost:3010/product/getp3?id3=2
        return productService.getById(id);
    }
}
